package com.hzqy.persistence.dao.system;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.ExcelExportTempVo;
import com.hzqy.web.vo.PmsOrgVo;
import com.hzqy.web.vo.YxtNmsykCourseVo;
import com.hzqy.web.vo.YxtNmsykLessonVo;
import com.hzqy.web.vo.stat.StatOffITVUserVo;
import com.hzqy.web.vo.system.SysConfigVo;

@Repository
public class SysUtilDao extends PersistenceDao<SysConfigVo, Integer>{
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	public List<PmsOrgVo> selectOrgByOrgName(String f_po_name){
		return getSqlSession().selectList(this.getNamespace() + "selectOrgByOrgName",f_po_name );
	}

	public List<ExcelExportTempVo> selectAllUserModelList() {
		return getSqlSession().selectList(this.getNamespace() + "selectAllUserModelList");
	}
	
	public int deleteOrder() {
		return getSqlSession().delete(this.getNamespace() + "deleteOrder");
	}
	
	public int deleteHQOrder() {
		return getSqlSession().delete(this.getNamespace() + "deleteHQOrder");
	}
	
	public int insertOrder(ExcelExportTempVo exportVo) {
		return getSqlSession().insert(this.getNamespace() + "insertOrder",exportVo);
	}
	
	public int insertHQOrder(ExcelExportTempVo exportVo) {
		return getSqlSession().insert(this.getNamespace() + "insertHQOrder",exportVo);
	}
	
	public int deleteUserOrg() {
		return getSqlSession().delete(this.getNamespace() + "deleteUserOrg");
	}
	
	public int deleteBICPUserOrg() {
		return getSqlSession().delete(this.getNamespace() + "deleteBICPUserOrg");
	}
	
	
	/**
	 * 插入全平台用户清单
	 * @param iter
	 * @return
	 */
	public int insertUserOrg(List<ExcelExportTempVo> exportVoList) {
		SqlSession ss = getSqlSession();
		int flag = 0;
		try {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("list", exportVoList);
			flag = ss.insert(this.getNamespace() + "insertUserOrg", map);
			if (flag < 1) {
				LOG.debug("用户清单入库失败：" + exportVoList.size());
			} else {
				LOG.debug("用户清单入库成功:" + exportVoList.size());
			}
		} catch (Exception e) {
			LOG.error("用户清单入库出错:" + exportVoList.size(), e);
			return 0;
		}
		return flag;
	}
	
	/**
	 * 插入全平台用户清单
	 * @param iter
	 * @return
	 */
	public int insertBICPUserOrg(List<ExcelExportTempVo> exportVoList) {
		SqlSession ss = getSqlSession();
		int flag = 0;
		try {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("list", exportVoList);
			flag = ss.insert(this.getNamespace() + "insertBICPUserOrg", map);
			if (flag < 1) {
				LOG.debug("用户清单入库失败：" + exportVoList.size());
			} else {
				LOG.debug("用户清单入库成功:" + exportVoList.size());
			}
		} catch (Exception e) {
			LOG.error("用户清单入库出错:" + exportVoList.size(), e);
			return 0;
		}
		return flag;
	}
	
	public Map<String,Object> selectDatabaseRuntime(){
		return getSqlSession().selectOne(this.getNamespace() + "selectDatabaseRuntime");
	}

	public int insertCourse(YxtNmsykCourseVo yxtNmsykCourseVo) {
		return getSqlSession().insert(this.getNamespace() + "insertCourse",yxtNmsykCourseVo);
	}

	public int insertLession(YxtNmsykLessonVo lessonVo) {
		return getSqlSession().insert(this.getNamespace() + "insertLession",lessonVo);
	}
	
	public int deleteOffITVUser() {
		return getSqlSession().delete(this.getNamespace() + "deleteOffITVUser");
	}
	public int insertOffITVUser(StatOffITVUserVo statOffITVUserVo) {
		return getSqlSession().insert(this.getNamespace() + "insertOffITVUser",statOffITVUserVo);
	}
	public int deleteUnsubscribeUserBill(String lastMonth,int f_ub_type) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lastMonth", lastMonth);
		map.put("f_ub_type", f_ub_type);
		return getSqlSession().delete(this.getNamespace() + "deleteUnsubscribeUserBill",map);
	}

	public List<ExcelExportTempVo> selectPlayTimeTop30 (String lastMonth,int page ,int count){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lastMonth", lastMonth);
		map.put("page", page);
		map.put("count", count);
		return getSqlSession().selectList("selectPlayTimeTop30",map);
	}

	public List<ExcelExportTempVo> selectPlayCountTop30 (String lastMonth,int page ,int count){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lastMonth", lastMonth);
		map.put("page", page);
		map.put("count", count);
		return getSqlSession().selectList("selectPlayCountTop30",map);
	}

	public List<ExcelExportTempVo> selectConsumptionTop30 (String lastMonth,int page ,int count){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("lastMonth", lastMonth);
		map.put("page", page);
		map.put("count", count);
		return getSqlSession().selectList("selectConsumptionTop30",map);
	}

	public List<String> selectOrgNameList (int f_po_parentId){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_po_parentId", f_po_parentId);
		return getSqlSession().selectList("selectOrgNameList",map);
	}

	public List<String> selectAccountList (int f_cc_type){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("f_cc_type", f_cc_type);
		return getSqlSession().selectList("selectAccountList",map);
	}
}